<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>社区管理 - 管理后台</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            color: #333;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            background: rgba(255, 255, 255, 0.95);
            padding: 20px;
            border-radius: 15px;
            margin-bottom: 30px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }

        .header h1 {
            color: #667eea;
            font-size: 2.5rem;
            font-weight: 700;
            text-align: center;
            margin-bottom: 10px;
        }

        .nav-tabs {
            display: flex;
            gap: 10px;
            margin-top: 20px;
            flex-wrap: wrap;
        }

        .nav-tab {
            padding: 12px 20px;
            background: #f8f9fa;
            color: #666;
            text-decoration: none;
            border-radius: 8px;
            transition: all 0.3s ease;
            font-weight: 500;
            border: 2px solid transparent;
        }

        .nav-tab:hover {
            background: #e9ecef;
            transform: translateY(-2px);
        }

        .nav-tab.active {
            background: #667eea;
            color: white;
            border-color: #5a6fd8;
        }

        .content {
            background: rgba(255, 255, 255, 0.95);
            padding: 30px;
            border-radius: 15px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }

        .page-title {
            color: #667eea;
            font-size: 2rem;
            font-weight: 600;
            margin-bottom: 30px;
            text-align: center;
        }

        .stats-summary {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .stat-card {
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
            padding: 20px;
            border-radius: 12px;
            text-align: center;
            box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
        }

        .stat-number {
            font-size: 2rem;
            font-weight: bold;
            margin-bottom: 5px;
        }

        .stat-label {
            font-size: 0.9rem;
            opacity: 0.9;
        }

        .posts-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            background: white;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        }

        .posts-table th {
            background: #667eea;
            color: white;
            padding: 15px;
            text-align: left;
            font-weight: 600;
        }

        .posts-table td {
            padding: 15px;
            border-bottom: 1px solid #eee;
            vertical-align: top;
        }

        .posts-table tr:hover {
            background: #f8f9fa;
        }

        .post-title {
            font-weight: 600;
            color: #333;
            margin-bottom: 5px;
        }

        .post-meta {
            font-size: 0.85rem;
            color: #666;
        }

        .badge {
            padding: 4px 8px;
            border-radius: 12px;
            font-size: 0.75rem;
            font-weight: 500;
            margin-right: 5px;
        }

        .badge-pinned {
            background: #ffc107;
            color: #856404;
        }

        .badge-category {
            background: #e9ecef;
            color: #495057;
        }

        .action-buttons {
            display: flex;
            gap: 8px;
            flex-wrap: wrap;
        }

        .btn {
            padding: 6px 12px;
            border: none;
            border-radius: 6px;
            text-decoration: none;
            font-size: 0.8rem;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            display: inline-flex;
            align-items: center;
            gap: 4px;
        }

        .btn-pin {
            background: #ffc107;
            color: #856404;
        }

        .btn-pin:hover {
            background: #e0a800;
        }

        .btn-unpin {
            background: #6c757d;
            color: white;
        }

        .btn-unpin:hover {
            background: #545b62;
        }

        .btn-delete {
            background: #dc3545;
            color: white;
        }

        .btn-delete:hover {
            background: #c82333;
        }

        .btn-view {
            background: #17a2b8;
            color: white;
        }

        .btn-view:hover {
            background: #138496;
        }

        .empty-state {
            text-align: center;
            padding: 60px 20px;
            color: #666;
        }

        .empty-state h3 {
            margin-bottom: 10px;
            color: #999;
        }

        @media (max-width: 768px) {
            .container {
                padding: 10px;
            }

            .header h1 {
                font-size: 2rem;
            }

            .nav-tabs {
                justify-content: center;
            }

            .posts-table {
                font-size: 0.9rem;
            }

            .posts-table th,
            .posts-table td {
                padding: 10px 8px;
            }

            .action-buttons {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header class="header">
            <h1>🛠️ 管理后台</h1>
            <nav class="nav-tabs">
                <a href="/admin" class="nav-tab">📊 控制面板</a>
                <a href="/admin/users" class="nav-tab">👥 用户管理</a>
                <a href="/admin/knowledge" class="nav-tab">📚 科普管理</a>
                <a href="/admin/forum" class="nav-tab active">💬 社区管理</a>
                <a href="/admin/points_shop" class="nav-tab">🛒 积分商城</a>
                <a href="/admin/settings" class="nav-tab">⚙️ 系统设置</a>
            </nav>
        </header>

        <div class="content">
            <h1 class="page-title">💬 社区管理</h1>

            <div class="stats-summary">
                <div class="stat-card">
                    <div class="stat-number">{{ posts|length }}</div>
                    <div class="stat-label">总帖子数</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number">{{ posts|selectattr('is_pinned')|list|length }}</div>
                    <div class="stat-label">置顶帖子</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number">{{ posts|sum(attribute='reply_count') }}</div>
                    <div class="stat-label">总回复数</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number">{{ posts|sum(attribute='like_count') }}</div>
                    <div class="stat-label">总点赞数</div>
                </div>
            </div>

            {% if posts %}
            <table class="posts-table">
                <thead>
                    <tr>
                        <th>帖子信息</th>
                        <th>作者</th>
                        <th>统计</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for post in posts %}
                    <tr>
                        <td>
                            <div class="post-title">{{ post.title }}</div>
                            <div class="post-meta">
                                {% if post.category %}
                                <span class="badge badge-category">{{ post.category }}</span>
                                {% endif %}
                                {{ post.created_at.strftime('%Y-%m-%d %H:%M') }}
                            </div>
                        </td>
                        <td>{{ post.author.username }}</td>
                        <td>
                            <div>💬 {{ post.reply_count }} 回复</div>
                            <div>👍 {{ post.like_count }} 点赞</div>
                            <div>👀 {{ post.view_count }} 浏览</div>
                        </td>
                        <td>
                            {% if post.is_pinned %}
                            <span class="badge badge-pinned">📌 置顶</span>
                            {% endif %}
                        </td>
                        <td>
                            <div class="action-buttons">
                                <a href="/forum/post/{{ post.id }}" class="btn btn-view" target="_blank">
                                    👁️ 查看
                                </a>
                                {% if post.is_pinned %}
                                <a href="/admin/forum/toggle_pin/{{ post.id }}" class="btn btn-unpin"
                                   onclick="return confirm('确定要取消置顶吗？')">
                                    📌 取消置顶
                                </a>
                                {% else %}
                                <a href="/admin/forum/toggle_pin/{{ post.id }}" class="btn btn-pin"
                                   onclick="return confirm('确定要置顶此帖子吗？')">
                                    📌 置顶
                                </a>
                                {% endif %}
                                <a href="/admin/forum/delete_post/{{ post.id }}" class="btn btn-delete"
                                   onclick="return confirm('确定要删除此帖子吗？此操作不可撤销！')">
                                    🗑️ 删除
                                </a>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
            {% else %}
            <div class="empty-state">
                <h3>📝 暂无帖子</h3>
                <p>社区中还没有任何帖子</p>
            </div>
            {% endif %}
        </div>
    </div>

    <script>
        // 自动刷新页面数据
        setInterval(function() {
            // 可以添加AJAX刷新逻辑
        }, 30000);
    </script>
</body>
</html>